package top.csjss.hospital.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import top.csjss.hospital.entity.SysMenu;
import top.csjss.hospital.entity.SysMenuExample;
import top.csjss.hospital.mapper.SysMenuMapper;
import top.csjss.hospital.service.SysMenuService;

import java.util.List;

/**
 * @Author ztf
 * @Date 11:14 2021/10/19
 **/
@Service
public class SysMenuServiceImpl implements SysMenuService {
    @Autowired
    private SysMenuMapper sysMenuMapper;

    @Override
    public List<SysMenu> findAll() {
        //封装条件
        SysMenuExample example = new  SysMenuExample();
        SysMenuExample.Criteria criteria = example.createCriteria();
        criteria.andAvailableEqualTo(1);
        return sysMenuMapper.selectByExample(example);
    }

    @Override
    public PageInfo<SysMenu> findByTitle(String title, Integer page, Integer limit) {
        //开启分页
        PageHelper.startPage(page, limit);

        //封装查询条件
        SysMenuExample example = new SysMenuExample();
        SysMenuExample.Criteria criteria = example.createCriteria();
        if (!StringUtils.isEmpty(title)){
            criteria.andTitleEqualTo(title);
        }
        //查询
        List<SysMenu>list= sysMenuMapper.selectByExample(example);
        //封装数据
        PageInfo<SysMenu> pageInfo=new PageInfo<>(list);

        return pageInfo;
    }
}
